var express = require('express');
var router = express.Router();
var leave = require("../model/leave/leave");

/* GET home page. */
router.get('/userlist', function(req, res, next) {
    if (req.session.userid) {
        //根据该用户编号 获取请假信息

        res.render("leave/userlist"); //应该带该用户的的所有请假记录
    } else {
        res.redirect("/users/login");
    }

});
router.post("/add", function(req, res, next) {
    //接收数据
    var id = req.session.userid;
    var username = req.session.username;
    var reason = req.body.reason;
    var start = req.body.start;
    var end = req.body.end;
    var attach = req.body.img;
    var leaveInfo = {
        userid: id,
        username: username,
        reason: reason,
        start: new Date(start),
        end: new Date(end),
        attach: attach,
        leavetype: 1
    }


    leave.add(leaveInfo).then(function(result) {
        res.json(result);
    })




    // console.log(id);
    // console.log(username);

})

module.exports = router;